/**
 * 新增修改完成调用 modalFormOk方法 编辑弹框组件ref定义为modalForm
 * 高级查询按钮调用 superQuery方法  高级查询组件ref定义为superQueryModal
 * data中url定义 list为查询列表  delete为删除单条记录  deleteBatch为批量删除
 */
import { filterObj } from '@/utils/util'
import { deleteRequest, getRequest, postRequest } from '@/api/baseRequest'
import Vue from 'vue'
// import {ACCESS_TOKEN, TENANT_ID} from '@/store/mutation-types'
import store from '@/store'
import { listQrtz } from '@/api/mange/qrtz'

export const TduckListMixin = {
  data() {
    return {
      description: '',
      // 查询条件
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {}
    }
  },
  mounted() {
    if (!this.disableMixinCreated) {
      console.log(' -- mixin created -- ')
      this.getList()
      // 初始化字典配置 在自己页面定义
      // this.initDictConfig()
    }
  },
  computed: {
    //token header
    /*tokenHeader() {
            let head = {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)}
            let tenantid = Vue.ls.get(TENANT_ID)
            if (tenantid) {
                head['tenant-id'] = tenantid
            }
            return head
        }*/
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      console.log(this.queryParams)
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    getList() {
      this.loading = true
      let param = this.getQueryParams()
      getRequest(this.url.list, param).then((response) => {
        // console.log(response)
        this.dataList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    getQueryParams() {
      //获取查询条件
      let sqp = {}
      var param = Object.assign(sqp, this.queryParams)
      return filterObj(param)
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    onClearSelected() {
      this.ids = []
    }
  }
}
